//
//  STcommodityListViewController.m
//  赛拓
//
//  Created by 王磊 on 8/9/16.
//  Copyright © 2016 立金所. All rights reserved.
//

#import "STCommodityListViewController.h"
#import "STCommodityListCollectionView.h"
#import "STCommodityBean.h"
#import "STCommodityDetailViewController.h"
@interface STCommodityListViewController ()<STBaseViewDelegate>
@property (nonatomic ,strong) STCommodityListCollectionView *collectionView;
@end

@implementation STCommodityListViewController

- (void)initSubviews {
    [super initSubviews];
    
    STCommodityListCollectionView *collectionView = [STCommodityListCollectionView instanceWithFrame:self.view.bounds];
    
//    collectionView.contentInset = UIEdgeInsetsMake( 30, 0, 30, 0);
    
    self.collectionView = collectionView;
    
    collectionView.backgroundColor = [UIColor redColor];
    
    collectionView.mDelegate = self;
    
    [self.view addSubview:collectionView];
    
}

- (void)loadNewData {
    
    [self.collectionView.mj_header beginRefreshing];
    
    NSArray *data = @[
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"15",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"18",
                          
                          @"cid":@"",
                          @"type":@(1)
                          
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"20",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"20",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"1",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"15",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"18",
                          
                          @"cid":@"",
                          @"type":@(1)
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"20",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"20",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(2)
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"20",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          
                          },
                      @{
                          
                          @"icon":@"http://7xwkri.com2.z0.glb.qiniucdn.com/p1.png",
                          @"name":@"高岭土",
                          @"price":@"20",
                          
                          @"time":@"123123123",
                          @"cid":@"",
                          @"type":@(1)
                          
                          }
                      ];
    
    
    NSArray *goods = [STCommodityBean mj_objectArrayWithKeyValuesArray:data];
    
    [self.collectionView updateData:goods];
    
    [self.collectionView.mj_header endRefreshing];
    
}
- (void)loadMoreData {
    
    
}
- (void)onItemClick:(STItemClickType)itemType withData:(id)data forIndexPath:(NSIndexPath *)indexPath {
    
    switch (itemType) {
        case STItemClickTypeItem:
        {
            
            self.block(@(itemType),data ,indexPath);
            
        }
            break;
            
        default:
            break;
    }
}
@end
